package com.tony.blog.server.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: CaptchaConfig
 * @Auther: 皮蛋布丁
 * @Date: 2021/07/12/21:00
 * @Description: 验证码自定义配置
 */
@Configuration
public class CaptchaConfig {

    /*方式一@Bean
    public DefaultKaptcha producer() {
        Properties properties = new Properties();

        //是否有图片边框
        properties.setProperty("kaptcha.border", "no");
        //边框颜色
        properties.setProperty("kaptcha.border.color", "105,179,90");
        //字体颜色
        properties.setProperty("kaptcha.textproducer.font.color", "blue");
        //图片宽
        properties.setProperty("kaptcha.image.width", "135");
        //图片高
        properties.setProperty("kaptcha.image.height", "30");
        //字体大小
        properties.setProperty("kaptcha.textproducer.font.size", "30");
        //session key
        properties.setProperty("kaptcha.session.key", "kaptchaCode");
        //验证码长度
        properties.setProperty("kaptcha.textproducer.char.length", "5");
        //使用那些字符生成验证码
        properties.setProperty("kaptcha.textproducer.char.string", "ACDEFHKPRSTWX345679");
        //使用哪些字体
        properties.setProperty("kaptcha.textproducer.font.names", "Arial,Courier,cmr10,宋体,楷体,微软雅黑");
        //干扰线颜色
        properties.setProperty("kaptcha.noise.color", "black");
        //图片样式阴影
        properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy");

        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }*/

    @Bean
    public DefaultKaptcha producer() {
        Properties properties = new Properties();
        //是否有图片边框
        properties.put("kaptcha.border", "no");
        //边框颜色
        properties.put("kaptcha.textproducer.font.color", "black");
        //文字间隔
        properties.put("kaptcha.textproducer.char.space", "5");
        //设置字体
        properties.put("kaptcha.textproducer.font.names", "Arial,Courier,cmr10,宋体,楷体,微软雅黑");
        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
